package com.taskforwork.getAllNewColmFromSql;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;

/**
 * @author: hfxiang
 * @Description:
 * @date: 2022/11/3 16:45
 */
public class Main {
    public static void main(String[] arg) throws IOException {
        //目录
        String dirt= "D:\\temp\\myHXRsql\\LSK\\";
        //信息1
        String msg1 ;
        File file = new File(dirt);
        String[] list = file.list();
        List<String> fileNameList = Arrays.asList(list);
        msg1="目录："+dirt+"\n"+"文件数量："+fileNameList.size()+"\n开始分析...\n";
        List<String> result=new ArrayList();
        for (String fileName : fileNameList) {
            String filePath = dirt+fileName;
            File sqlFile = new File(filePath);
            result.addAll(readUsingFileReader(sqlFile));
        }
        System.out.println("表名\t\t\t\t\t\t\t\t字段名\t\t\t\t\t\t\t\t类型");
        for (String row : result) {
            String[] params = row.replace("'","").split(",");
            System.out.println(params[0]+"\t\t\t\t"+params[1]+"\t\t\t\t"+params[2]);
        }
        return;
    }
    //返回新增字段的语句
    private static List<String> readUsingFileReader(File file) throws IOException {
        List<String> result=new ArrayList();
        FileReader fr = new FileReader(file);
        BufferedReader br = new BufferedReader(fr);
        String line;
        String patternAnnotation = "^(-- ).+$";
        String patternAddFunction = "^(CALL Pro_Temp_ColumnWork\\(.+\\);?)$";
        while((line = br.readLine()) != null){
            //排除注释
//            if (Pattern.matches(patternAnnotation,line)){
//                System.out.println(line);
//            }
            if (Pattern.matches(patternAddFunction,line)){
                String res = line.replace("CALL Pro_Temp_ColumnWork(", "");
                res = res.replace(");", "");
                result.add(res);
            }
        }
        br.close();
        fr.close();
        return result;
    }
}
